//
//  MessageView.m
//  wangzhe
//
//  Created by 李 佳伟 on 2018/3/21.
//  Copyright © 2018年 李 佳伟. All rights reserved.
//

#import "MessageView.h"
#import "JTCSM.h"
#import "MyDoubleLabelView.h"
@interface MessageView ()
{
    CGFloat space;
}
@property (nonatomic,strong) UIImageView *alertView;
@property (nonatomic,strong) UIImageView *headerView;
@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UILabel *timeLabel;
@property (nonatomic,strong) UILabel *contentLabel;
@property (nonatomic,strong) MyDoubleLabelView *doubleView;
@end

@implementation MessageView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
- (id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        UIImageView *backIamgeV = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
        backIamgeV.image = [UIImage imageNamed:@"大背景.png"];
        [self addSubview:backIamgeV];
        
        CGFloat imageheight = frame.size.height*0.2376;
        CGFloat imagewidth = frame.size.width*0.9355-20;
        CGFloat labelHeight = frame.size.height*0.1980198;
        CGFloat timeLabelHeight = frame.size.height*0.01599;
        space = (frame.size.width-imagewidth)/2;
        
        self.headerView = [[UIImageView alloc]initWithFrame:CGRectMake(space, space, imagewidth, imageheight)];
        self.headerView.image = [UIImage imageNamed:@"文章图片.png"];
        [self addSubview:self.headerView];
        CGFloat alertImagesize = 40;
        self.alertView = [[UIImageView alloc]initWithFrame:CGRectMake(self.headerView.LC_width-20-alertImagesize, 0, alertImagesize, alertImagesize)];
        self.alertView.image = [UIImage imageNamed:@"新.png"];
        self.alertView.hidden = YES;
        [self.headerView addSubview:self.alertView];
        
        UIView *headerBackView = [[UIView alloc]initWithFrame:CGRectMake(0, self.headerView.LC_height-50, self.headerView.LC_width, 50)];
        headerBackView.backgroundColor = RGBACOLOR(0, 0, 0, 0.28);
        [self.headerView addSubview:headerBackView];
        
        self.titleLabel = [UILabel initWithFrame:CGRectMake(15, self.headerView.LC_height-50, self.headerView.LC_width-30, 50)text:@"" font:14 textAlignment:NSTextAlignmentLeft texcolor:[df colorWithHexString:@"ffffff" alpha:1] backgroundColor:nil];
        [self.headerView addSubview:self.titleLabel];
        
        self.timeLabel = [UILabel initWithFrame:CGRectMake(space, KVIEW_Y(self.headerView)+space, frame.size.width-2*space, timeLabelHeight) text:@"07/18 蜂窝喔" font:10 textAlignment:NSTextAlignmentLeft texcolor:[df colorWithHexString:@"999999" alpha:1] backgroundColor:nil];
        [self addSubview:self.timeLabel];
        
        [df newlineViewWithHeightofTop:KVIEW_Y(self.timeLabel)+10 superView:self spacing:space color:RGBACOLOR(241, 241, 241, 1) lineHeight:1];
        
        self.contentLabel = [UILabel initWithFrame:CGRectMake(space, KVIEW_Y(self.timeLabel)+20, frame.size.width-2*space, labelHeight) text:@"的是一个汉语汉字，普通话读音是de,dí,dì,dī（粤语读音为dik1），其居现代汉语使用量之首，有着漫长的演变史。用在定语的后面，也可以用在主谓短语中间，现代汉语56008个常..." font:12 textAlignment:NSTextAlignmentLeft texcolor:[df colorWithHexString:@"666666" alpha:1] backgroundColor:nil];
        [self addSubview:self.contentLabel];
        self.contentLabel.numberOfLines = 0;
        CGFloat lineTop = frame.size.height*0.7855;
        
        [df newlineViewWithHeightofTop:lineTop superView:self spacing:space color:RGBACOLOR(241, 241, 241, 1) lineHeight:1];
        
        CGFloat bottomViewHeight = frame.size.height*0.18151815-timeLabelHeight-20;
        
        self.doubleView = [[MyDoubleLabelView alloc]initWithFrame:CGRectMake(space, lineTop, self.headerView.LC_width*2/3, bottomViewHeight) leftTitleFontsize:14 titlecolor:[df colorWithHexString:@"222222" alpha:1] contentFontsize:12 contentcolor:[df colorWithHexString:@"666666" alpha:1]];
        [self addSubview:self.doubleView];
        [self.doubleView InsertSpacesetvalueWithModel:@{KDoubleLabelTitle:@"分享奖励",KDoubleLabelContent:@"分享成功后可随机获取神秘奖励"} changeLabelY:10];
        
        
        [df lineViewWithWidthtofLeft:KVIEW_X(self.doubleView) superView:self.doubleView spacing:10 color:RGBACOLOR(241, 241, 241, 1) lineWidth:1];
        
        CGFloat shareIamgeSize = 30;
        CGFloat shareimagespace = (self.headerView.LC_width/3-30)/2+space/2;
        CGFloat shareImageTop = self.doubleView.LC_y+(bottomViewHeight-shareIamgeSize)/2;
        UIImageView *shareImageView = [[UIImageView alloc]initWithFrame:CGRectMake(KVIEW_X(self.doubleView)+shareimagespace, shareImageTop, shareIamgeSize, shareIamgeSize)];
        [shareImageView setImage:[UIImage imageNamed:@"分享icon.png"]];
        [self addSubview:shareImageView];
        
        UILabel *bottomLabel = [UILabel initWithFrame:CGRectMake(space, frame.size.height-28-timeLabelHeight, self.headerView.LC_width, timeLabelHeight) text:@"已有23943位用户参加活动" font:9 textAlignment:NSTextAlignmentCenter texcolor:[df colorWithHexString:@"999999" alpha:1] backgroundColor:nil];
        [self addSubview:bottomLabel];
        
        
    }
    return self;
}

- (void)setValueWithModel:(id)model isShowNewImage:(BOOL)isshow{
    self.titleLabel.text = [NSString stringWithFormat:@"%@",model];
    self.alertView.hidden = !isshow;
}

@end
